package com.test.testCode.test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class SortTestB {
    public static void main(String[] args) {
        List<Stu> list = new ArrayList<>();
        list.add(new Stu("kk","1"));
        list.add(new Stu("kk","2"));
        list.add(new Stu("kk","3"));
        list.add(new Stu("kk","1"));
        list.add(new Stu("kk","2"));
        list.add(new Stu("kk","3"));
        list.add(new Stu("kk","2"));
        list.add(new Stu("kk","1"));

        List<String> subjects = list.stream().map(Stu::getSubject).distinct().collect(Collectors.toList());
        for (String s : subjects){
            System.out.println(s);
        }
    }
}

class Stu{
    private String name;
    private String subject;

    public Stu(String name, String subject) {
        this.name = name;
        this.subject = subject;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", subject='" + subject + '\'' +
                '}';
    }
}
